<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>编辑国家信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/web/res/css/xadmin.css">
    <script src="/web/res/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/web/res/js/xadmin.js"></script>
</head>

<body style="background-color: white;">
<div class="layui-fluid" id="orderEdit">
    <form class="layui-form layui-form-pane" id="formsubmit" lay-filter="formsubmit"
          style="width: 500px;margin:20px auto" action="/manage/app/country/saveOrUpdate">
        <input id="id" name="id" type="hidden" value="${(obj.id?c)!''}">
        <div class="layui-form-item">
            <label class="layui-form-label">国家名</label>
            <div class="layui-input-block">
                <input type="text" name="name" required lay-verify="required" autocomplete="off"
                       class="layui-input" value="${(obj.name)!''}"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">国家简写</label>
            <div class="layui-input-block">
                <input type="text" name="abbreviation" required lay-verify="required" autocomplete="off"
                       class="layui-input" value="${(obj.abbreviation)!''}"/>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-upload">
                <label class="layui-form-label lable-text-center">国家图片</label>
                <div class="upload-list" id="uploadlist">
                    <div class="upload-imgBox">
                        <input type="hidden"  id="imgpathhide" value="${(obj.image)!''}"  class="layui-input"/>
                        <div class="upload-cancel">x</div>
                        <img  src="${(obj.image)!''}" class="upload-select-img">
                    </div>
                    <div class="upload-img" id="uploadtemplate" style="display:none;">+</div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">国家代码</label>
            <div class="layui-input-block">
                <input type="text" name="code" required lay-verify="required" autocomplete="off"
                       class="layui-input" value="${(obj.code)!''}"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">国家代码</label>
            <div class="layui-input-block">
                <input type="text" name="sort" required lay-verify="required" autocomplete="off"
                       class="layui-input" value="${(obj.sort)!''}"/>
            </div>
        </div>

        <!-- <div class="layui-form-item">
            <label class="layui-form-label">购买方式</label>
            <div class="layui-input-block">
                <select name="goumaifangshi" id="goumaifangshi" lay-filter="typeone" lay-verify="required"
                        style="margin: 0;">
                    <option value="1" <#if obj?exists && obj.goumaifangshi?exists><#if (obj.goumaifangshi)?number == 1?number>selected</#if></#if>>钻石</option>
                    <option value="2" <#if obj?exists && obj.goumaifangshi?exists><#if (obj.goumaifangshi)?number == 2?number>selected</#if></#if>>金豆</option>
                </select>
            </div>
        </div> -->


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn layui-btn-radius" lay-submit lay-filter="save">&emsp;保存&emsp;
                </button>
                <button type="button" class="layui-btn layui-btn-primary layui-btn-radius" onclick="xadmin.close()">
                    &emsp;返回&emsp;
                </button>
            </div>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'upload'], function () {
        let $ = layui.$;
        var form = layui.form;
        var upload = layui.upload;
        form.render();
        // 重新添加删除功能
        $('.upload-cancel').on('click', function(event){
            let self = $(event.currentTarget);
        self.parent().remove();
        event.stopPropagation();

        if ($("input[id='imgpathhide']").length < 1) {
            $('#uploadtemplate').show();
        } else {
            $('#uploadtemplate').hide();
        }
    })
        ;


        upload.render({
            elem: '#uploadtemplate',
            // auto: false,
            url: '/after/gift/uploadLiveImg',
            accept: 'images',
            acceptMime: 'image/*',
            choose: function (obj) {
            },
            done: function (res) {
                    $('#uploadlist').prepend(
                        '<div class="upload-imgBox">  <input type="hidden"  id="imgpathhide" value="' + res.data.name + '"  class="layui-input"/><div class="upload-cancel">x</div><img  src="' + res.data.name + '" class="upload-select-img"></div>');
                    $(".upload-cancel").on("click", function (e) {
                        $(this).parent().remove();
                        if ($("input[id='imgpathhide']").length < 1) {
                            $('#uploadtemplate').show();
                        }
                    })
                    if ($("input[id='imgpathhide']").length >= 1) {
                        $('#uploadtemplate').hide();
                    }
            }
        });
        //  单文件上传
        upload.render({
            elem: '#test5'
            , url: '/after/gift/upOssImg'
            , accept: 'file'
            , choose: function (obj) {
                obj.preview(function (index, file, result) {
                    $('#excelname').val(file.name);

                });
            }
            , before: function (obj) {
                layer.load();
            }
            , done: function (res) {
                layer.closeAll('loading');
                $('#excelname').val(res.data.name);
                $("#gifteffectss").val(res.data.imgname);
                layer.msg('上传成功');
                console.log("-----" + $("#gifteffectss").val());
            }
        });


        $.fn.extend({
            serializeObject: function () {
                var obj = {}; //声明一个对象
                $.each(this.serializeArray(), function (index, field) {
                    obj[field.name] = field.value; //通过变量，将属性值，属性一起放到对象中
                })
                return obj;
            }
        });
        form.on('submit(' + $("button[lay-submit]:eq(0)").attr("lay-filter") + ')', function (data) {
            console.log(data);
            $("input[id='imgpathhide']").each(function (index, ele) {
                $(this).attr("name", "image");
            });
            $("input[id='imgpathhide2']").each(function (index, ele) {
                $(this).attr("name", "frameUrl");
            });
            $("input[id='excelname']").each(function (index, ele) {
                $(this).attr("name", "svgaaddress");
            });
            layer.confirm('确认要保存吗？', function (index) {
                loading = layer.load(1);
                console.log(form.val("formsubmit"));
                ajaxPost($, $("#formsubmit").attr("action"), $("#formsubmit").serializeObject(), function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                            xadmin.father_reload();
                        });
                    } else {
                        layer.close(loading);
                        layer.msg(data.msg, {icon: 2, time: 3000}, function () {

                        });
                    }
                });
            });
        });
    });
</script>
</body>

</html>